<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>20-阶段小结：Tab栏切换</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
      ul li {
        list-style: none;
      }
      li {
        float: left;
        border: 1px solid #cccccc;
        margin-left: -1px;
        line-height: 40px;
        width: 80px;
        text-align: center;
      }
      ul {
        overflow: hidden;
      }
      .current {
        background-color: skyblue;
        display: block !important;
      }
      .container {
        width: 500px;
        height: 300px;
        border: 1px solid #ccc;
        text-align: center;
        line-height: 300px;
        font-size: 24px;
        font-weight: 700;
        color: red;
        margin: -35px 0 0 39px;
        overflow: hidden;
      }
      .box {
        display: none;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <ul>
        <li
          v-for="(item, index) in arr"
          :key="index"
          v-bind:class="index == currentIndex ? 'current' : ''"
          @click="tabToggle(index)"
        >
          {{item}}
        </li>
      </ul>
      <br />
      <div class="container">
        <div
          class="box"
          v-bind:class="currentIndex ==index ? 'current' : ''"
          key="index"
          v-for="(item, index) in arr"
        >
          {{item}}
        </div>
      </div>
    </div>
    <script>
      var vm = new Vue({
        el: '#app',
        data: {
          arr: ['橘子', '香蕉', '荔枝'],
          currentIndex: 0,
        },
        methods: {
          tabToggle: function (index) {
            this.currentIndex = index;
          },
        },
      });
    </script>
  </body>
</html>
